<?php

namespace Database\Factories;

use App\Models\Question;
use Illuminate\Database\Eloquent\Factories\Factory;

class QuestionFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = Question::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        $types = ['radio', 'checkbox', 'judge', 'fill', 'short', 'subsystem'];
        $content = ['1+1=?', '这是一个填空题测试,中国的四大名著有(*),(*),(*),(*)'];

        $type = $types[rand(0, 2)];

        switch ($type) {
            case 'radio': $successAnswer = 65; break;
            case 'checkbox': $successAnswer = "[65,66]"; break;
            case 'judge': $successAnswer = rand(0, 1); break;
        }

        return [
            'user_id' => rand(1, 3),
            'category_id' => rand(11, 16),
            'type' => $type,
            'level' => rand(1, 5),
            'title' => '测试' . $this->faker->randomNumber(2),
            'content' => $content[rand(0, 1)],
            'fraction' => $this->faker->randomNumber(2),
            'status' => rand(0, 1),
            'answer' => json_decode('{"65":"1","66":"2","67":"3","68":"4"}'),
            'success_answer' => $successAnswer
        ];
    }
}
